package com.qfedu.service.impl;

import com.qfedu.mapper.SubItemMapper;
import com.qfedu.model.SubItem;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.service.ISubItemService;
import com.qfedu.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 概述:
 *
 * @Author: Tbh
 * @Date: 2022/7/3 0:05
 */

@Service
public class SubItemServiceImpl implements ISubItemService {

    @Autowired
    private SubItemMapper subItemMapper;

    @Override
    public PageResult findPage(QueryPageBean queryPage) {

        Integer currentPage = queryPage.getCurrentPage();
        Integer pageSize = queryPage.getPageSize();

        List<SubItem> page = subItemMapper.findPage((currentPage - 1) * pageSize,pageSize);

        Long count = subItemMapper.count();

        return new PageResult(count,page);
    }

    @Override
    @Transactional
    public int addSubItem(SubItem subItem) {
        subItem.setSuid(UUIDUtils.uuid());
        int row = subItemMapper.addSubItem(subItem);
        return row;
    }

    @Override
    public SubItem findBySuid(String suid) {
        SubItem subItem = subItemMapper.findBySuid(suid);
        return subItem;
    }

    @Override
    @Transactional
    public int edit(SubItem subItem) {
        subItem.setUpdatetime(new Date());
        int row = subItemMapper.updateSubItem(subItem);
        return row;
    }

    @Override
    @Transactional
    public int deleteBySuid(String suid) {
        int row = subItemMapper.deleteBySuid(suid);
        return row;
    }

    @Override
    public List<SubItem> findAll() {
        return subItemMapper.findAll();
    }
}
